package csce315.group10.androidapp;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

import android.os.Parcel;
import android.os.Parcelable;

@Root
public class Contact implements Parcelable{
	/* private instance variables */
	private String name;
	private String phone;
	private String address;
	private String email;
	private String position;
	@Element
	private String password;

	public Contact(@Attribute(name = "name") String _name,@Element(name="phone",required=false)String _phone,@Element(name="address",required=false) String _address,
			@Element(name="email",required=false) String _email,@Element(name="position",required=false)String _position){
		name = _name;
		phone = _phone;
		address = _address;
		email = _email;
		position = _position;
		/* by default password is password until changed */
		password = "password";
	}
	/* constructor used by Parcelable */
	public Contact(Parcel source){
        /*
         * Reconstruct from the Parcel
         */
        name = source.readString();
        phone = source.readString();
        address = source.readString();
        email = source.readString();
        position = source.readString();
        password = source.readString();
  }
	/* used in serialization to pass in an intent */
	public int describeContents() {
		return hashCode();
	}
	/* used to serialize data to pass in an intent*/
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(name);
	    dest.writeString(phone);
	    dest.writeString(address);
	    dest.writeString(email);
	    dest.writeString(position);
	    dest.writeString(password);
	}
	/* used to create an event object from Parcelable */
	public static final Parcelable.Creator CREATOR =
    	new Parcelable.Creator() {
            public Contact createFromParcel(Parcel in) {
                return new Contact(in);
            }
 
            public Contact[] newArray(int size) {
                return new Contact[size];
            }
        };
    /* Modifiers */
    public void setPassword(String current_pw,String new_pw){
    	if(password.equals(current_pw)){
    		password = new_pw;
    	}
    }
    public void set_phone(String _phone){
    	phone = _phone;
    }
    public void set_address(String _address){
    	address = _address;
    }
    public void set_email(String _email){
    	email = _email;
    }
    public void set_position(String _position){
    	position = _position;
    }
	/* Accessors */
    @Attribute(name = "name")
	public String get_name(){
    	return name;
    }
    @Element(name = "phone",required=false)
	public String get_phone(){
    	return phone;
    }
    @Element(name = "address",required=false)
	public String get_address(){
    	return address;
    }
    @Element(name = "email",required=false)
	public String get_email(){
    	return email;
    }
    @Element(name = "position")
	public String get_position(){
    	return position;
    }
    public String get_password(){
    	return password;
    }
	public boolean check_password(String pw){
		return password.equals(pw);
	}
	
	public Contact getContact(){
		return this;
	}
}